package de.davidneu.gpxviewer.units 
{
    /**
     * @author david
     */
    public class UnitSet 
    {
    	private var _speedLabel:String;
    	private var _heightLabel:String;
    	private var _distanceLabel:String;
    	private var _speedFactor:Number;
    	private var _heightFactor:Number;
    	private var _distanceFactor:Number;
    	
    	public function UnitSet(speedLabel:String, heightLabel:String, distanceLabel:String, speedFactor:Number = 1, heightFactor:Number = 1, distanceFactor:Number = 1)
    	{
            _speedLabel = speedLabel;
            _heightLabel = heightLabel;
            _distanceLabel = distanceLabel;
            _speedFactor = speedFactor;
            _heightFactor = heightFactor;
            _distanceFactor = distanceFactor;
        }
        
        public function convertSpeed(val:Number):Number
        {
        	return val * _speedFactor;
        }
        
        public function convertHeight(val:Number):Number
        {
        	return val * _heightFactor;
        }
        
        public function convertDistance(val:Number):Number
        {
            return val * _distanceFactor;
        }
        
        public function viewSpeed(val:Number, precision:int = 2):String
        {
        	return viewNumber(convertSpeed(val), precision) + ' ' + _speedLabel;
        }
        
        public function viewHeight(val:Number, precision:int = 2):String
        {
            return viewNumber(convertHeight(val), precision) + ' ' + _heightLabel;
        }
        
        public function viewDistance(val:Number, precision:int = 2):String
        {
            return viewNumber(convertDistance(val), precision) + ' ' + _distanceLabel;
        }
        
        private function viewNumber(val:Number, precision:int = 2):String
        {
        	var f:Number = Math.pow(10, precision);
            return (Math.round(val*f)/f).toString();
        }
    }
}
